<template>
	<view class="content">
		<view class="top-pic">
			<uni-list>
				<uni-list-item title="个人资料" showArrow @click="toPro" link />
				<uni-list-item title="关于润隆汇" showArrow @click="toHome" link />
			</uni-list>
			<uni-list class="app">
				<uni-list-item title="账号与安全" showArrow @click="toAccount" link />
			</uni-list>
		</view>
		<view class="exit">
			<button type="success" @click="logoutFun">退出登录</button>
		</view>
		<view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {

			}
		},
		methods: {
			...mapMutations(['saveCartList']),
			//跳转个人资料
			toPro() {
				uni.navigateTo({
					url: "/pages/user/profile"
				})
			},
			//跳转 关于润隆汇
			toHome() {
				uni.navigateTo({
					url: "/pages/app/home"
				})
			},
			//跳转 账号与安全
			toAccount() {
				uni.navigateTo({
					url: "/pages/tool/account"
				})
			},
			//退出登录
			logoutFun() {
				const thas = this
				// 自定义退出弹框
				uni.showModal({
					title: '提示',
					content: '确认要退出当前登录？',
					success: function(res) {
						if (res.confirm) {
							// 直接退出当前应用
							thas.logout()

						} else if (res.cancel) {
							console.log('用户点击取消')
						}
					}
				})
			},
			async logout() {
				const {
					status,
					data,
					msg
				} = await this.$api.user.logout()
				if (status == 200) {
					uni.removeStorageSync("token")
					uni.removeStorageSync("userInfo")
					uni.removeStorageSync("permission")
					uni.removeStorageSync("customer")
					uni.removeStorageSync("car")
					uni.removeStorageSync("optionGoods")
					//获取用户购物车
					this.saveCartList(null);
					//重定向到登录页面
					uni.navigateTo({
						url: '/pages/user/login'
					})
				}
			}
		}
	}
</script>

<style scoped lang="less">
	.content {
		width: 100%;
		height: 100%;

		.top-pic {
			width: 100%;
			height: 100%;

			.app {
				margin-top: 10upx;
			}
		}

		.exit {
			margin-top: 10upx;
		}
	}
</style>